<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * create parts of the menu for static-pages
 * used from core.php
 * use topmenu.tpl.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
function categoryMenu($refPage, $page, $title, $refValidate)
{
	$refPage->assign('categoryList', _('Productlist'));

	db::getInstance()->orderBy('category_order', 'ASC');
	db::getInstance()->where('category_active', 1);
	db::getInstance()->where('category_top', 0);
	$cols = Array('category_id', 'category_name', 'category_order', 'category_top');
	$result = db::getInstance()->get("category", null, $cols);

	$buffer = array();
	$buffer = sortCategorys($result, true);
	$categoryList = array();

	foreach ($buffer as $entry)
	{
		if ($page == 'article' and $entry['category_id'] == $_SESSION['categoryMenux'])
		{
			$classname = 'mainlevel-active';
		}
		elseif ($page == 'category' and $title == $entry['category_id'])
		{
			$classname = 'mainlevel-active';
			$_SESSION['categoryMenux'] = $entry['category_id'];
		}
		else
		{
			$classname = 'mainlevel';
		}
		$categoryList[] = array('categoryLink' =>
		 '<a title="' . $entry['category_name'] . '" style="display:block;" class="' . $classname .
		 '" href="/index.php?page=category&title=' . $entry['category_id'] .
		 '&name=' . $entry['category_name'] . '">' . $entry['category_name'] . '</a>');
	}
	$refPage->assign('categoryMenu', $categoryList);
}

?>